<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"/>
    <title>概况</title>
    <link rel="stylesheet" type="text/css" href="../../leaflet/leaflet.css"/>
    <link rel="stylesheet" type="text/css" href="../../leaflet/leaflet.marker.highlight.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/map.css"/>
    <script src="../../js/lib/jquery-3.2.1.min.js"></script>
    <script src="../../leaflet/leaflet.js"></script>
    <script src="../../leaflet/leaflet.marker.highlight.js"></script>
</head>
<body>
<div id="map"></div>

<div id="layerControl">
    <div onclick="floorControl.click(0)" class="floorBtn">F5</div>
    <div onclick="floorControl.click(1)" class="floorBtn">F4</div>
    <div onclick="floorControl.click(2)" class="floorBtn">F3</div>
    <div onclick="floorControl.click(3)" class="floorBtn">F2</div>
    <div onclick="floorControl.click(4)" class="floorBtn">F1</div>
</div>
<div id="toolPanel">

</div>
<script src="../../js/common.js"></script>
<script src="../../js/mapSource.js"></script>
<script src="../../js/layer.js"></script>
<script src="../../js/UI/floorControl.js"></script>
<script src="../../js/indoorMap.js"></script>
<script src="../../js/pgrouting.js"></script>
<script src="../../js/measure.js"></script>
<script src="../../js/plotting.js"></script>
<script>
    layerManager.setMap(map);
    layerManager.setBaseLayer(BaseLayers.getMapBoxUrl(), BaseLayers.getLayerDetails(0).id, BaseLayers.getToken());
    map.fitBounds([[34.26327, 112.715096],
        [34.989103, 114.21727]]);

    map.addEventListener('click', function (e) {
        var geomText = latlngToGeomText(e.latlng);
        var params = {
            geoText: geomText
        };
        $.get('http://192.168.1.165:8081/getSmokeBySingleClick', params, function (data, status) {
            if (status == "success") {
                if (data.length > 0) {
                    console.log(data[0].geom);
                    var geom = JSON.parse(data[0].geom);
                    console.log(geom.coordinates);
                    addFlicker(geom.coordinates[1], geom.coordinates[0]);
                }
            }
        });
    });

    function latlngToGeomText(latlng) {
        var lat = latlng.lat;
        var lng = latlng.lng;
        var geomText = "POINT(" + lat + " " + lng + ")";
        return geomText;
    }

    var locateMarker;

    function addLocateMarker(lat, lng) {
        if (map.hasLayer(locateMarker)) {
            map.removeLayer(locateMarker);
        }
        locateMarker = L.marker([lat, lng], {highlight: 'temporary'}).addTo(map);
    }
    //接收蓝牙结果
    function addLocation(x, y) {
        var b = -0.00000813 * x - 0.0000079 * y + 113.5582199;
        var l = -0.00000742 * y + 0.00000647 * x + 34.8252123;
        addFlicker(l, b);
    }
    //移除标记
    function stopLocation(){
     map.removeLayer(flicker);
    }
</script>
</body>
</html>